package com.lmh.util;

import com.lmh.data.DBConfigure;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created by Liumh on 2018/5/25.
 */
public class DBUtil {

    private static Connection conn = DBConfigure.getConnection();

    public static void execute(String sql, Object... strs){
        try {
            PreparedStatement statement = conn.prepareStatement(sql);
            if(strs != null && strs.length > 0){
                for (int i=0;i<strs.length;i++){
                    if(i+1 != strs.length){
                        statement.setString(i+1, (String) strs[i]);
                    }else{
                        statement.setDate(i+1, (Date) strs[i]);
                    }
                }
                statement.execute();
                statement.close();
                conn.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
